import {
  //养护管理
  GetCompany,
  GetClass,
  GetZClass,
  ReportSource,
  GetQueryProblem,
  Edit,
  Delete,
  CloseProblem,
  AssignProblem,
  GetMediafiles,
} from '@/services/landspace';

export default {
  namespace: 'maintain',
  state: {
    yhdwList: [], //养护单位
    sblyList: [], //上报来源
    wtlxList: [], //问题类型 大类
    wtlxZList: [], //问题类型 小类
    yhglTb: { data: [] }, //养护管理查询表格数据
    error: '',
    data: {},
  },

  effects: {
    /* 养护管理 */
    // 获取养护单位
    *fetchGetCompany({ payload, callback }, { call, put }) {
      const response = yield call(GetCompany, payload);
      yield put({
        type: 'queryYhdw',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 获取照片
    *fetchGetMediafiles({ payload, callback }, { call, put }) {
      const response = yield call(GetMediafiles, payload);
      if (callback) callback(response);
    },
    // 上报来源
    *fetchReportSource({ payload, callback }, { call, put }) {
      const response = yield call(ReportSource, payload);
      yield put({
        type: 'querySbly',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 获取问题类型 大类
    *fetchGetClass({ payload, callback }, { call, put }) {
      const response = yield call(GetClass, payload);
      yield put({
        type: 'queryWtlx',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 获取问题类型 小类
    *fetchGetZClass({ payload, callback }, { call, put }) {
      const response = yield call(GetZClass, payload);
      yield put({
        type: 'queryWtlxZ',
        payload: response,
      });
      if (callback) callback(response);
    },
    // 养护管理-查询
    *fetchGetQueryProblem({ payload, callback }, { call, put }) {
      const response = yield call(GetQueryProblem, payload);
      yield put({
        type: 'queryYhgl',
        payload: response,
      });
      if (callback) callback(response);
    },
    //删除记录
    *fetchYhglDelete({ payload, callback }, { call, put }) {
      const response = yield call(Delete, payload);
      if (callback) callback(response);
    },
    //结案记录
    *fetchYhglCloseProblem({ payload, callback }, { call, put }) {
      const response = yield call(CloseProblem, payload);
      if (callback) callback(response);
    },
    //编辑记录
    *fetchYhglEdit({ payload, callback }, { call, put }) {
      const response = yield call(Edit, payload);
      if (callback) callback(response);
    },
     //分派处理
     *fetchAssignProblem({ payload, callback }, { call, put }) {
      const response = yield call(AssignProblem, payload);
      if (callback) callback(response);
    },
    
  },

  reducers: {
    //养护单位
    queryYhdw(state, action) {
      return {
        ...state,
        yhdwList: action.payload,
      };
    },
    //上报来源
    querySbly(state, action) {
      return {
        ...state,
        sblyList: action.payload,
      };
    },
    //问题类型 大类
    queryWtlx(state, action) {
      return {
        ...state,
        wtlxList: action.payload.data,
      };
    },
    //问题类型 小类
    queryWtlxZ(state, action) {
      return {
        ...state,
        wtlxZList: action.payload,
      };
    },
    //养护管理-查询
    queryYhgl(state, action) {
      return {
        ...state,
        yhglTb: action.payload,
      };
    },

  }
};
